package com.example.parkinglot.service.Impl;

import com.example.parkinglot.mapper.ParkingSpaceOrderMapper;
import com.example.parkinglot.model.PageResult;
import com.example.parkinglot.model.ParkingSpaceOrder;
import com.example.parkinglot.service.ParkingSpaceOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ParkingSpaceOrderServiceImpl implements ParkingSpaceOrderService {
    @Resource
    ParkingSpaceOrderMapper orderMapper;
    @Override
    public PageResult<ParkingSpaceOrder> findPageResult(ParkingSpaceOrder condition, int page, int pageSize) {
        PageResult<ParkingSpaceOrder> result=new PageResult<ParkingSpaceOrder>();
        result.setCode(0);
        //获取总记录数
        Map<String,Object> params=new HashMap<String, Object>();
        params.put("start",(page-1)*pageSize);
        params.put("limit",pageSize);
        int totalCount=orderMapper.findCountByMap(params);
        result.setCount(totalCount);
        //获取查询数据
        List<ParkingSpaceOrder> list =orderMapper.findListByMap(params);;
        result.setData(list);

        return result;
    }

    @Override
    public void save(ParkingSpaceOrder order) {
        orderMapper.insert(order);
    }

    @Override
    public ParkingSpaceOrder findByOrderId(String order_id) {
        return orderMapper.findByOrderId(order_id);
    }

    @Override
    public void deleteByOrderId(String order_id) {
        orderMapper.deleteByOrderId(order_id);
    }

    @Override
    public void update(ParkingSpaceOrder order) {
        orderMapper.update(order);
    }
}
